-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.
local lu = require 'luaunit'
local mcu_service = require 'mcu.mcu_service'

TestMcuService = {}
function TestMcuService:test_get_vrd_info()
    mcu_service.bcu_mcu_collection = {
        [1] = {
            sub_component_info_list = {
                vrd = 'test'
            },
            get_vrd_info = function(mcu_obj)
                return mcu_obj.sub_component_info_list
            end
        }
    }
    local ok, vrd_info = pcall(mcu_service.get_vrd_info, mcu_service, '010101')
    lu.assertEquals(ok, true)
    lu.assertEquals(vrd_info.vrd, 'test')
end

function TestMcuService:test_listen_vrd_abnormal()
    local value = {0, 0, 0, 8, 8, 8, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
    local i = 0
    local obj = {
        get_id = function()
            return "MCU123"
        end,
        interface = {
            get_system_event = function()
                i = i + 1
                return value[i]
            end,
        },
        get_vrd_dump_info = function(id)
            print(string.format("[Test] get_vrd_dump_info called with mcu_id: %s", id))
        end
    }
    local ok = pcall(mcu_service.listen_vrd_abnormal, mcu_service, obj)
    lu.assertEquals(ok, true)
end

function TestMcuService:test_on_dump_vrd_cb()
    mcu_service.bcu_mcu_collection = {
        {
            get_id = function()
                return "MCU123"
            end,
            get_vrd_dump_info = function(id)
                print(string.format("[Test] get_vrd_dump_info called with mcu_id: %s", id))
            end,
            get_vrd_log = function()
                return {1, 0}
            end
        }
    }
    local ok = pcall(mcu_service.on_dump_vrd_cb, mcu_service, 1, '/vrd_reg_dump')
    lu.assertEquals(ok, true)
end